<template>
  <div class="app-container">
    <div>
      <p class="dialogTitle title">当前地震事件:
        <span v-if="currentEvent">{{ currentEvent.eventName }}</span>
        <span v-else>请在地震事件管理中设置当前地震事件</span>
      </p>
    </div>

    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="100px" v-show="showSearch">
      <el-form-item label="省" prop="province">
        <el-select v-model="queryParams.province" placeholder="请选择省" @change="chooseProvince" clearable value-key="id">
          <el-option v-for="item in provinceData" :key="item.id" :label="item.name" :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-select v-model="queryParams.city" placeholder="请选择市" @change="chooseCity" clearable value-key="id">
          <el-option v-for="item in cityData" :key="item.id" :label="item.name" :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="区/县" prop="area">
        <el-select v-model="queryParams.area" placeholder="请选择县" @change="choosearea" clearable value-key="id">
          <el-option v-for="item in areaData" :key="item.id" :label="item.name" :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="房屋用途" prop="houseUseType">
        <el-select v-model="queryParams.houseUseType" placeholder="请选择房屋用途" clearable>
          <el-option v-for="item in option" :key="item.dictItemCode" :label="item.dictItemName"
            :value="item.dictItemCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-radio-group v-model="dataFrom" @change="chooseRadio">
        <el-radio :label="1">报表</el-radio>
        <el-radio :label="2">普查</el-radio>
        <el-radio :label="3" @click="clickRadio($event)">文件</el-radio>
      </el-radio-group>
    </el-row>
    <el-row :gutter="10" class="mb8">
      <!-- :rules="{versionCode:[{ required: true, message: '请选择版本！', trigger: 'change' }]}" -->
      <el-form :model="versionForm" ref="versionFormRef">
        <el-form-item label="版本：" prop="versionCode" :rules="[{ required: true, message: '请选择版本！', trigger: 'change' }]">
          <span>{{ query.versionCode }}</span>
          <el-button @click="selectVersion" :style="{ 'margin-left': query.versionCode ? '20px' : '' }">选择版本</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" @click="calculateArea">总建筑面积</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" stripe row-key="id" @selection-change="handleSelectionChange" border
      :span-method="objectSpanMethod">
      <!--<el-table-column type="selection" align="center" :reserve-selection="true" width="55" />
            <el-table-column label="序号" align="center" width="55">
                <template #default="scope">
                    <span>{{ (queryParams.page - 1) * queryParams.rows + scope.$index + 1 }}</span>
                </template>
            </el-table-column>-->
      <el-table-column label="评估子区" align="center" prop="evaluationSubareaName" width="200" show-overflow-tooltip />
      <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="区/县" align="center" prop="county" />
      <el-table-column label="房屋用途" align="center" prop="housePurposeCode" width="150">
        <template #default="scope">
          {{ getHouseUseType(scope.row.housePurposeCode) }}
        </template>
      </el-table-column>
      <el-table-column label="总建筑面积（平米）" align="center" prop="">
        <el-table-column label="I类" align="center" prop="v1Area" />
        <el-table-column label="II类" align="center" prop="v2Area" />
        <el-table-column label="III-1类" align="center" prop="v3Area" />
        <el-table-column label="III-2类" align="center" prop="v4Area" />
        <el-table-column label="IV类" align="center" prop="v5Area" />
        <el-table-column label="V-1类" align="center" prop="v6Area" />
        <el-table-column label="V-2类" align="center" prop="v7Area" />
        <el-table-column label="V-3类" align="center" prop="v8Area" />
        <el-table-column label="VI类" align="center" prop="v9Area" />
        <el-table-column label="VII类" align="center" prop="v10Area" />
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button type="text" @click="handleEdit(scope.row)">修改</el-button>
          <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
      @pagination="getList" />

    <el-dialog :title="title" v-model="open" width="600px" append-to-body>
      <el-form ref="addRef" label-width="160px" :model="form" :rules="rules">
        <el-row style="margin: 20px 0;">
          <el-col>
            <el-form-item label="I类" prop="v1Area" required>
              <el-input v-model="form.v1Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="II类" prop="v2Area" required>
              <el-input v-model="form.v2Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="III-1类" prop="v3Area">
              <el-input v-model="form.v3Area" placeholeder="" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="III-2类" prop="v4Area" required>
              <el-input v-model="form.v4Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="IV类" prop="v5Area" required>
              <el-input v-model="form.v5Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="V-1类" prop="v6Area" required>
              <el-input v-model="form.v6Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="V-2类" prop="v7Area" required>
              <el-input v-model="form.v7Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="V-3类" prop="v8Area" required>
              <el-input v-model="form.v8Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="VI类" prop="v9Area" required>
              <el-input v-model="form.v9Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="VII类" prop="v10Area" required>
              <el-input v-model="form.v10Area" placeholeder=""></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="save">保 存</el-button>
          <el-button @click="open = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
      <p></p>
      <el-link @click="handleDownload(currentEvent.attachId)" :underline="false" target="_blank" v-if="currentEvent.attachId">
          <span class="el-icon-document"> {{ fileName }} </span>
        </el-link>
        <p></p>
      <el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url"
        :disabled="upload.isUploading" :before-upload="handleFileBeforeUpload" :on-progress="handleFileUploadProgress"
        :on-error="handleFileUploadError" :on-success="handleFileSuccess" :data="{xsemId:currentEvent.id}" :auto-upload="false" drag>
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <template #tip>
          <div class="el-upload__tip text-center">
            <span>仅允许导入xls、xlsx格式文件。</span>
            <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
              @click="importTemplate('总建筑面积导入模板.xlsx')">下载模板</el-link>
          </div>
        </template>
      </el-upload>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitFileForm" >确 定</el-button>
          <el-button @click="upload.open = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 普查对话框 -->
    <el-dialog title="输入教育系统面积占比" v-model="generalSurvey" width="400px" append-to-body>
      <p></p>
      <el-form ref="addRef" label-width="150px" :model="form" :rules="rules">
        <el-form-item label="教育系统面积占比" prop="ratio" required>
          <el-input-number v-model="form.ratio" :min="0" :max="1" :step="0.1" :precision="2"></el-input-number>
          <!-- <el-input v-model="form.ratio" placeholeder="" ></el-input> -->
        </el-form-item>
        <div>说明: 输入教育系统面积占教育医疗类面积的占比,默认占比为0.50</div>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="generalSurvey = false">确 定</el-button>
          <el-button @click="generalSurvey = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog title="选择版本" v-model="openLeader" width="900px" append-to-body @close="closeVersicode">
      <p></p>
      <el-form ref="selectRef" :model="pageSize">
        <el-row style="margin: 20px 0;">
          <el-col :span="8">
            <el-form-item label="数据级别" label-width="80px">
              <!-- <el-input v-model="pageSize.dataRangeCountry" placeholder="请选择数据类别" clearable /> -->
              <el-select v-model="pageSize.dataRangeCountry" placeholder="请选择数据级别" style="width:192px"
                @change="chooseFormScope1" clearable>
                <el-option v-for="item in [{ value: 1, label: '国家级' }, { value: 2, label: '省级' }]" :key="item.value"
                  :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="省" label-width="80px">
              <!-- <el-input v-model="pageSize.dataRangeProvince" placeholder="请选择省" clearable /> -->
              <el-select v-model="pageSize.dataRangeProvince" placeholder="请选择省" @change="chooseProvince" clearable
                value-key="name">
                <el-option v-for="item in provinceData" :key="item.id" :label="item.name" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="市" label-width="80px">
              <!-- <el-input v-model="pageSize.dataRangeCity" placeholder="请选择市" clearable /> -->
              <el-select v-model="pageSize.dataRangeCity" placeholder="请选择市" @change="chooseCity" clearable
                value-key="name">
                <el-option v-for="item in cityData" :key="item.id" :label="item.name" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="区县" label-width="80px">
              <!-- <el-input v-model="pageSize.dataRangeArea" placeholder="请选择区县" clearable /> -->
              <el-select v-model="pageSize.dataRangeArea" placeholder="请选择区县" clearable value-key="name">
                <el-option v-for="item in areaData" :key="item.id" :label="item.name" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button type="primary" @click="handleQuery1" style="float: right;">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table ref="selectMunchRef" :data="leaderList" stripe>
        <el-table-column label="单选" width="55px">
          <template #default="scope">
            <el-radio :label="scope.row.id" v-model="selectRadio"
              @click.native.stop.prevent="getCurrentRow(scope.row)">&nbsp;</el-radio>
          </template>
        </el-table-column>
        <el-table-column label="序号" align="center" width="55">
          <template #default="scope">
            <span>{{ (pageSize.page - 1) * pageSize.rows + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="版本号" align="center" prop="versionCode" />
        <el-table-column label="数据名称" align="center" prop="dataName" />
        <el-table-column label="数据范围" align="center" prop="dataRange" />
        <el-table-column label="上传人" align="center" prop="uploadUser" />
        <el-table-column label="上传时间" align="center" prop="uploadTime" />
      </el-table>
      <pagination v-show="pageSize.total > 0" :total="pageSize.total" v-model:page="pageSize.page"
        v-model:limit="pageSize.rows" @pagination="handleQuery1" />
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="querySelect" :disabled="selectRadioStatus">确
            定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
  
<script setup name="floorArea">
import { getCurrentEvent } from '@/api/comprehensiveInformation/seismicEvents'
import { dataMethod } from '@/utils/spanTable.js'
import { getToken, } from "@/utils/auth";
import useEventStore from "@/store/modules/event";
import { getAllList, getDetail, updateData, del, getSubList, getProvinceList, getAreaList, mathHouseCategoryArea,getName } from "@/api/directLossAssess/floorArea.js"
import { getDict } from "@/api/system/dict";
import { uploadAdministrativeArea, page, getDataDoc } from '@/api/disasterManage/kilometerGrid/index.js'
import { getProvince, getChildArea } from "@/api/system/division";
import { ref } from 'vue';
const currentEvent = computed(() => useEventStore().currentEvent);
const { proxy } = getCurrentInstance();
const dataList = ref([]);
const ids = ref();
const loading = ref(false);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const showSearch = ref(true);
const open = ref(false);
const generalSurvey = ref(false);
const attachId = ref();
const title = ref();
const dataFrom = ref(1);
const spanObj = ref();
const option1 = ref([]);
const option = ref([]);
const provinceData = ref([]); //省
const cityData = ref([]); //市
const areaData = ref([]); //区、县
const versionForm = ref({})

/*** 导入参数 */
const upload = reactive({
  open: false,
  title: "",
  isUploading: false,
  headers: { token: "token " + getToken() },
  url: import.meta.env.VITE_APP_BASE_API + "/attachment/uploadFile"
});
const validatePositiveNumver = (rule, value, callback) => {
  if (/(^[1-9]\d*$)/.test(value)) {
    callback()
  } else if (!value) {
    callback(new Error('总建筑面积不能为空'))
  } else {
    callback(new Error('请输入正整数'))
  }
};
const data = reactive({
  queryParams: {
    page: 1,
    rows: 10,
    area: undefined,
    structureType: undefined,
  },
  form: {
  },
  rules: {
    v1Area: [{ required: true, message: "I类总建筑面积不能为空", trigger: "blur" }],
    v2Area: [{ required: true, message: "II类总建筑面积不能为空", trigger: "blur" }],
    v3Area: [{ required: true, message: "III-1类总建筑面积不能为空", trigger: "blur" }],
    v4Area: [{ required: true, message: "III-2类总建筑面积不能为空", trigger: "blur" }],
    v5Area: [{ required: true, message: "IV类总建筑面积不能为空", trigger: "blur" }],
    v6Area: [{ required: true, message: "V-1类总建筑面积不能为空", trigger: "blur" }],
    v7Area: [{ required: true, message: "V-2类总建筑面积不能为空", trigger: "blur" }],
    v8Area: [{ required: true, message: "V-3类总建筑面积不能为空", trigger: "blur" }],
    v9Area: [{ required: true, message: "VI类总建筑面积不能为空", trigger: "blur" }],
    v10Area: [{ required: true, message: "VII类总建筑面积不能为空", trigger: "blur" }],
  },
  query: {
    versionCode: '',
    tempVersionCode: '',
    dataName: '',
    dataType: '',
    dataRangeCountry: '',
    dataRangeProvince: '',
    dataRangeCity: '',
    dataRangeArea: '',
    versionStartTime: '',
    versionEndTime: '',
    uploadStartTime: '',
    uploadEndTime: '',
  },
  pageSize: {
    dataRangeCountry: '', //数据级别 1-国家级， 2-省级
    dataRangeProvince: '', //版本范围省id
    dataRangeCity: '', //版本范围市id
    dataRangeArea: '', //版本范围县区id
    page: 1,
    rows: 10,
    total: 0
  },
})
const { queryParams, form, rules, query, pageSize } = toRefs(data)

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  single.value = selection.length != 1;
  multiple.value = !selection.length;
  ids.value = selection.map((item) => item.id);
};
const openLeader = ref(false)
const selectionData = ref({})
function querySelect() {
  query.value.versionCode = selectionData.value.versionCode;
  versionForm.value.versionCode = selectionData.value.versionCode;
  openLeader.value = false;
  proxy.$refs.versionFormRef.clearValidate('versionCode');
}
function closeVersicode() {
  pageSize.value.dataRangeCountry = ''
  pageSize.value.dataRangeProvince = ''
  pageSize.value.dataRangeCity = ''
  pageSize.value.dataRangeArea = ''
}
const selectRadio = ref('')
const selectRadioStatus = ref(true)
function getCurrentRow(row) {
  if (selectRadio.value) {
    if (selectRadio.value == row.id) {
      selectRadio.value = ''
      selectionData.value = {};// 取消勾选就把回传数据清除
      selectRadioStatus.value = true
      return
    }
  }
  selectRadioStatus.value = false
  selectRadio.value = row.id;
  selectionData.value = row;
}
// 导出模版
function importTemplate(name) {
  proxy.downloadTemplate("/template/download", {
    fileName: name
  }, name);
};
const chooseFormScope1 = (value) => {
  if (value == "1") {//国家级
    pageSize.value.dataRangeProvince = "全国";
  } else {
    pageSize.value.dataRangeProvince = "";
  }
  pageSize.value.dataRangeCity = "";
  pageSize.value.dataRangeArea = "";
  form.value.dataRangeProvince = null;
  form.value.dataRangeCity = null;
  form.value.dataRangeArea = null;
  proxy.$refs['selectRef'].validateField(['dataRangeProvince']);
  cityData.value = [];
  areaData.value = [];
}
/** 提交上传文件 */
function submitFileForm() {
  proxy.$refs["uploadRef"].submit();
};

/** 打开导入表弹窗 */
function handleImport() {
  upload.title = "导入";
  upload.open = true;
}

/**文件上传前处理 */
function handleFileBeforeUpload(file) {
  proxy.$modal.loading("正在上传文件，请稍候...");
  return true
}

let fileName = ref('')
function getFileName(attachId) {
  getName(attachId).then(res=>{
    fileName.value = res
  })
}
function handleDownload(attachId) {
	var query = {
		attachId:attachId,
	}
	location.href = import.meta.env.VITE_APP_BASE_API + "/attachment/downLoadFile?attachId="+ encodeURIComponent(query.attachId);
}

const leaderList = ref([])
const provinceId = ref('')
const cityId = ref('')
const countyId = ref('')
function handleQuery1() {
  proxy.$modal.loading('等待中...');
  let params = {
    dataRangeCountry: pageSize.value.dataRangeCountry,
    dataRangeProvince: pageSize.value.dataRangeProvince == '全国' ? '' : provinceId.value,
    dataRangeCity: cityId.value,
    dataRangeArea: countyId.value,
    page: pageSize.value.page,
    rows: pageSize.value.rows
  }
  page(params).then(res => {
    leaderList.value = res.data.list
    pageSize.value.total = res.data.total
    proxy.$modal.closeLoading();
  }).catch(
    proxy.$modal.closeLoading()
  )
}
/**文件上传中处理 */
const handleFileUploadProgress = (event, file, fileList) => {
  upload.isUploading = true;
};
// 上传失败
function handleFileUploadError(err) {
  proxy.$modal.closeLoading();
  proxy.$modal.msgError("上传文件失败");
}
function selectVersion() {
  generalSurvey.value = false
  proxy.$modal.loading('等待中...');
  page({ ...pageSize.value }).then(res => {
    leaderList.value = res.data.list
    total.value = res.data.total
    openLeader.value = true
    proxy.$modal.closeLoading();
  }).catch(
    proxy.$modal.closeLoading()
  )
}
/** 文件上传成功处理 */
const handleFileSuccess = (response, file, fileList) => {
  upload.open = false;
  upload.isUploading = false;
  proxy.$modal.closeLoading();
  attachId.value = response.data[0].attachId;
  proxy.$refs["uploadRef"].handleRemove(file);
  proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +  response.message + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
  getCurrentEvent().then(res=>{
    const data = res.data?{id:res.data.xsemId,eventCode:res.data.eventCode,eventName:res.data.eventName,attachId:attachId.value ?attachId.value :currentEvent.value.attachId}:res.data;
    console.log(data,'ATTACHTID');
    useEventStore().changeCurrentEvent(data)
  })
  getList();
};

// 编辑
function handleEdit(row) {
  title.value = '总建筑面积';
  detail(row.xshcaId);
}

// 查看
function detail(id) {
  getDetail({ xshcaId: id }).then(res => {
    open.value = true;
    proxy.resetForm("addRef");
    form.value = res.data;
  })
}

// 保存
function save() {
  proxy.$refs["addRef"].validate(valid => {
    if (valid) {
      updateData({ ...form.value }).then(res => {
        proxy.$modal.msgSuccess("保存成功");
        open.value = false;
        getList();
      })
    }
  })

}

/** 删除按钮操作 */
function handleDelete(row) {
  let ids = row.xshcaId || ids.value;
  proxy.$modal
    .confirm("是否确认删除该信息，请确认是否要删除？",)
    .then(function () {
      return del(ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => { });
}
function chooseRadio(value) {
  if (value == 2) {
    generalSurvey.value = true;
  } else if (value == 3) {
  }
}
function clickRadio(e){
  if (e.target.tagName === 'INPUT') return 
  if(currentEvent.value.attachId){
    getFileName(currentEvent.value.attachId)
  }
  upload.open = true;
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dataList.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

// 合并列
function objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  //判断合并列
  const _row = spanObj.value[column.property] ? spanObj.value[column.property][rowIndex] : 1;
  const _col = _row > 0 ? 1 : 0;
  return {
    rowspan: _row,
    colspan: _col,
  }
}
function calculateArea() {
  proxy.$refs['versionFormRef'].validate(valid => {
    if (valid) {
      loading.value = true;
      mathHouseCategoryArea({ dataFrom: dataFrom.value, attachId: attachId.value?attachId.value :currentEvent.value.attachId, ratio: form.value.ratio, versionCode: query.value.versionCode }).then(response => {
        loading.value = false;
        getList();
      }).catch(() => loading.value = false)
    }
  })
}
/** 查询数据列表 */
function getList() {
  if (currentEvent.value) {
    loading.value = true;
    getAllList({ ...queryParams.value, xsemCode: currentEvent.value?.eventCode }).then(response => {
      dataList.value = response.data ? response.data : [];
      spanObj.value = dataMethod(dataList.value, ['evaluationSubareaName', 'province', 'city']);
      //total.value = response.data.total;
      loading.value = false;
    }).catch(() => loading.value = false)
  } else {
    dataList.value = [];
    //total.value = 0;
  }
}

/** 查询评估子区列表 */
function getSubLists() {
  if (currentEvent.value) {
    getSubList({ xsemId: currentEvent.value.id }).then(response => {
      option1.value = response.data;
    });
  }
}
/** 获取字典值 */
async function getDictData() {
  await getDict("fwyt").then(response => {
    option.value = response.data;
  });
}
function getHouseUseType(val) {
  var name = ''
  option.value.forEach(item => {
    if (item.dictItemCode == val) {
      name = item.dictItemName
      return
    }
  })
  return name
}
/** 获取省列表 */
function getProvinceData() {
  getProvinceList(currentEvent.value?.eventCode).then((response) => {
    provinceData.value = response.data;
  });
}

function chooseProvince(value) {
  queryParams.value.city = null;
  queryParams.value.area = null;
  queryParams.value.province = value.name;
  cityData.value = [];
  areaData.value = [];
  getChildArea(value.id).then((response) => {
    cityData.value = response.data;
  });
  /*provinceData.value.map((item) => {
    //遍历数据
    if (item.id == value.id) {
      if (
        item.name == "北京市" ||
        item.name == "天津市" ||
        item.name == "上海市" ||
        item.name == "重庆市"
      ) {
        cityData.value.push(JSON.parse(JSON.stringify(item)));
      } else {
        getChildArea(value.id).then((response) => {
          cityData.value = response.data;
        });
      }
      return;
    }
  });*/
}

function chooseCity(value) {
  queryParams.value.city = value.name;
  queryParams.value.area = null;
  areaData.value = [];
  getChildArea(value.id).then((response) => {
    areaData.value = response.data;
  });
}

function choosearea(value) {
  queryParams.value.area = value.name;
}

onMounted(() => {
  // setTimeout(() => {
  //   getList();
  //   getProvinceData();
  // }, 200)
  getDictData();
})

watch(currentEvent, () => {
  getList();
  getProvinceData();
}, {immediate: true})
</script>
  
<style scoped lang="scss">
.title {
  margin: 0 0 20px !important;
}

:deep(.el-table) th.el-table__cell {
  border-bottom: 1px solid #ffffff !important;
  border-right: 1px solid #ffffff !important;
}

:deep(.el-table) td.el-table__cell {
  border-bottom: 1px solid #ebeef5 !important;
  border-right: 1px solid #ebeef5 !important;
}
</style>
  
  